﻿using StaffingSystem.Business;
using StaffingSystem.EF;
using StaffingSystem.Models;
using StaffingSystem.Tool;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace StaffingSystem.Controllers
{
    public class TransferBossController : Controller
    {

        #region 辞职/升职列表
        // GET: TransferBoss
        JsonResult result;
        public ActionResult TransferB()
        {
            return View();
        }
        #endregion


        #region 列表查询
        [HttpPost]
        public ActionResult TransferB(PageViewModel page)
        {
            result = new JsonResult();

            Personnelinfor list = new Personnelinfor();
            PageModel<Postchange> pagemodel = new PageModel<Postchange>();
            pagemodel.PageSize = page.PageSize;
            pagemodel.PageNumber = page.PageNumber;
            pagemodel.TableName = "Postchange";
            pagemodel.PageKey = "Id";

            if (page.D_NameR != null)
            {
                pagemodel.Where = " D_Name='" + page.D_NameR + "' and BossNumber=''";
                if (page.TypeR != null)
                {
                    pagemodel.Where = " D_Name='" + page.D_NameR + "' and Type=" + page.TypeR + " and BossNumber=''";
                }
            }
            else
            {
                pagemodel.Where = " BossNumber=''";
            }
            pagemodel.OrderID = "Id";
            pagemodel.AscOrDesc = string.Empty;
            pagemodel = list.GetPageList(pagemodel);

            result.Data = new
            {
                Sate = 0,
                Message = "获取数据成功",
                Data = JsonTool.JsonSerializer(pagemodel)
            };
            return result;
        }
        #endregion


        #region 申请审批（信息修改）
        public ActionResult TransferBupd(int id)
        {
            Management db = new Management();
            Postchange td = db.Postchange.FirstOrDefault(a => a.Id == id);
            JsonResult result = new JsonResult();
            result.Data = new
            {
                State = 0,
                Message = "获取数据成功",
                Data = JsonTool.JsonSerializer(td)
            };
            return result;

        }
        public ActionResult TransferGet(TransferBview bview)
        {
            result = new JsonResult();
            Transfer tran = new Transfer();
            Loginon user = Session["JobNumber"] as Loginon;
            tran.BossNumber = user.JobNumber;//管理员登陆ID工号
            tran.Id = Convert.ToInt32(bview.Id);
            bool results;
            if (bview.TypeS == "1")
            {
                results = true;
            }
            else
            {
                results = false;
            }
            tran.Result = results;
            tran.Proposal = bview.res;

            Personnelinfor list = new Personnelinfor();
            if (list.Transfer_edit(tran) > 0)
            {
                result = DataHelper.GetResult(ExecuteState.Succeed, "审阅成功！", "");
            }
            else
            {
                result = DataHelper.GetResult(ExecuteState.Failed, "审阅失败！", "");
            }
            return result;
        }
        #endregion

    }
}